<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="../jqgrid.jsp"></jsp:include>
</head>
<script type="text/javascript">
var roomId="";
function fillData(formid){
	formid.find("#roomId").val(roomId);
}
function queryBuilding() {
	var url = "queryBuildingByJson.action";
	var types = "";
	$.ajax({
		type : "POST",
		url : url,
		dataType : "json",
		async : false,
		success : function(data) {
			$.each(data, function(i, item) {
				types += item["id"] + ":" + item["number"] + ";";
			});
		}
	});
	return types.substring(0, types.lastIndexOf(";"));
}
function queryRoomInfo() {
	var url = "queryRoomInfoByJson.action";
	var types = "";
	$.ajax({
		type : "POST",
		url : url,
		dataType : "json",
		async : false,
		success : function(data) {
			$.each(data, function(i, item) {
				types += item["id"] + ":" + item["area"] + "平米("+item["room"]+"室"+item["parlour"]+"厅"+item["kitchen"]+"厨"+item["toilet"]+"卫);";
			});
		}
	});
	return types.substring(0, types.lastIndexOf(";"));
}
	$(document).ready(function() {
		jQuery("#roomlist").jqGrid({
			url : 'queryRoom.action',
			autowidth : true,
			datatype : "json",
			colNames : [ 'id', '楼号#','面积(平方米)','房号','楼层'],
			colModel : [ {
				name : 'id',
				index : 'id',
				width : 10,
				editable : false,
				align:"center",
				hidden:false,
				searchoptions : {
					sopt : [ 'eq', 'ne' ]
				}
			}, {
				name : 'bNumber',
				index : 'bNumber',
				width : 80,
				align : "center",
				editable : true,
				edittype:"select",
				editoptions : {
					value:queryBuilding
				},
				editrules:{
					required:true
				},
				searchoptions : {
					sopt : [ 'eq', 'ne' ]
				}
			}, {
				name : 'riArea',
				index : 'riArea',
				width : 80,
				align : "center",
				editable : true,
				edittype:"select",
				editoptions:{
					value:queryRoomInfo
				},
				searchoptions : {
					sopt : [ 'eq', 'ne' ]
				}
				
			}, {
				name : 'roomCode',
				index : 'roomCode',
				width : 80,
				align : "center",
				editable : true,
				editrules:{
					required:true,
					integer:true
				},
				searchoptions : {
					sopt : [ 'eq', 'ne' ]
				}
			}, {
				name : 'storey',
				index : 'storey',
				width : 80,
				align : "center",
				editable : true,
				editrules:{
					required:true,
					integer:true
				},
				searchoptions : {
					sopt : [ 'eq', 'ne' ]
				}
			}],
			rowNum : 10,
			rowList : [ 10, 20, 30 ],
			pager : '#roomgridPager',
			sortname : 'id',
			viewrecords : true,
			onSelectRow:function(rowid,status){
				var data = $("#roomlist").getRowData(rowid);
				 jQuery("#roomRepairInfolist").setGridParam({
					 url:"queryRoomRepairInfo.action?roomId="+data.id
					 }).trigger("reloadGrid"); 
				 roomId=data.id;
			},
			jsonReader : {
				repeatitems : false
			},
			sortorder : "desc",
			caption : "房子列表",
			editurl:"editRoom.action"
		});
		jQuery("#roomlist").jqGrid('navGrid', '#roomgridPager', {
			edit : true,
			add : true,
			del : false
		}, {}, {}, {},{multipleSearch:true});
		
		
		jQuery("#roomRepairInfolist").jqGrid({
			//url : 'queryRoomRepairInfo.action',
			autowidth : true,
			datatype : "json",
			colNames : [ 'id','roomId', '登记时间','维修时间','是否完成','备注'],
			colModel : [ {
				name : 'id',
				index : 'id',
				width : 55,
				editable : false,
				hidden:true
			}, {
				name : 'roomId',
				index : 'roomId',
				width : 10,
				hidden:true,
				editable : true,
				editrules:{
					required:true
				}
			}, {
				name : 'registerTime',
				index : 'registerTime',
				width : 80,
				align : "center",
				editable : true,
				formatter:"date",
				editrules:{
					required:true,
					date:true
				},
				formatoptions:{"newformat":"Y-m-d"},
				 editoptions: {
		              size: 10, 
		              maxlengh: 10,
		              dataInit: function(element) {
		                  $(element).datepicker({ dateFormat: 'yy-mm-dd'});
		              }
		          }
			}, {
				name : 'repairTime',
				index : 'repairTime',
				width : 80,
				align : "center",
				editable : true,
				formatter:"date",
				editrules:{
					required:true,
					date:true
				},
				formatoptions:{"newformat":"Y-m-d"},
				 editoptions: {
		              size: 10, 
		              maxlengh: 10,
		              dataInit: function(element) {
		                  $(element).datepicker({ dateFormat: 'yy-mm-dd'});
		              }
		          }
			}, {
				name : 'finish',
				index : 'finish',
				width : 80,
				align : "center",
				editable : true,
				edittype : "select",
				editoptions : {
					value : 'true:是;false:否'
				},
				formatter : function(cellvalue, options, row) {
					if (cellvalue == true) {
						return "是";
					} else {
						return "否";
					}
				}
			}, {
				name : 'remark',
				index : 'remark',
				width : 80,
				align : "center",
				editable : true
			}],
			rowNum : 10,
			rowList : [ 10, 20, 30 ],
			pager : '#roomRepairInfogridPager',
			sortname : 'id',
			viewrecords : true,
			jsonReader : {
				repeatitems : false
			},
			sortorder : "desc",
			caption : "维修记录列表",
			editurl:"editRepairInfo.action"
		});
		jQuery("#roomRepairInfolist").jqGrid('navGrid', '#roomRepairInfogridPager', {
			edit : true,
			add : true,
			del : true,
			search:false
		}, {}, {afterShowForm : fillData}, {},{multipleSearch:true});
	});
</script>
<body>
	<div align="center">
		<table id="roomlist"></table>
		<div id="roomgridPager"></div>
	</div>
	<div align="center">
		<table id="roomRepairInfolist"></table>
		<div id="roomRepairInfogridPager"></div>
	</div>
</body>
</html>